package com.navidove.appspotlight.model.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.navidove.appspotlight.model.bo.SysParam;
import com.navidove.appspotlight.model.dao.SysParamDao;
import com.navidove.appspotlight.model.service.SysParamService;

@Service
public class SysParamServiceImpl implements SysParamService {

	@Autowired
	private SysParamDao sysParamDao;

	public Map<String, String> getStringParamMap() {
		Map<String, String> rtnVal = new HashMap<String, String>();
		
		List<SysParam> list = sysParamDao.getAll();
		for (SysParam p : list) {
			rtnVal.put(p.getParamName(), p.getParamValue());
		}
		return rtnVal;
	}
	
	public void saveSysParam(String name, String value) {
		SysParam param = sysParamDao.get(name);
		Date now = new Date(); 
				
		if (param == null) {
			param = new SysParam();
			param.setParamName(name);
			param.setCrtAt(now);
		}
		param.setParamValue(value);
		param.setUpdAt(now);
		
		sysParamDao.save(param);
	}
}
